package com.atguigu.sparkcore.util

import com.atguigu.cm.util.MySparkContextCMUtil
import org.apache.spark.SparkContext

/**
 * 获取sparkContext工具类
 * author 剧情再美终是戏
 * mail 13286520398@163.com
 * date 2020/1/8 19:21 
 * version 1.0
 **/
object MySparkContextUtil {


  /**
   * 获取sparkContext
   *
   * author 剧情再美终是戏
   * date 2020/1/8 19:44
   *
   * @param args main方法入参,格式为name::value,以::拼接
   * @return org.apache.spark.SparkContext
   *         version 1.0
   **/
  def get(args: Array[String]): SparkContext = {
    this.get(args = args, isLocal = true)
  }

  /**
   * 获取sparkContext
   *
   * author 剧情再美终是戏
   * date 2020/1/9 7:37
   *
   * @param args    args main方法入参,格式为name::value,以::拼接
   * @param isLocal 是否本地模式
   * @return void
   *         version 1.0
   **/
  def get(args: Array[String], isLocal: Boolean): SparkContext = {
    MySparkContextCMUtil.get(args, isLocal)
  }

  /**
   * 关闭sparkContext资源
   *
   * author 剧情再美终是戏
   * date 2020/1/8 19:33
   *
   * @param sc sparkContext
   * @return void
   *         version 1.0
   **/
  def close(sc: SparkContext): Unit = {
    MySparkContextCMUtil.close(sc)
  }

}
